<?php
$this->headTitle($this->translator('shopping_cart_list_page_title'));

    $this->headScript()
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.tools/jquery.tools.js');
?>
<style type="text/css">
    .cart table{
        width: 100%;
        border-top: 0px;
        border-bottom: 0px;
    }
    .cart .caption td{
        font-weight: bold;
        background: #BCBBB9;
    }
    .cart tr.caption:hover td{
        font-weight: bold;
        background: #BCBBB9;
    }
    .cart tbody tr:hover td{
        background: #EFEDED;
    }
    .inline_block{
        display: inline-block;
        width: 100%;
    }
    .inline_block .col_33{
        float:left;
        width:33.3%;
    }
    .inline_block .col_33 input{
        cursor: pointer;
    }
    .clear_fix{
        clear: both;
    }
    .cart_bottom{
        margin-bottom: 10px;
    }
    .cart .amount div label{
        font-weight: bold;
    }
    .tooltip {
        display:none;
        background:#BCBBB9;
        height:auto;
        width:200px;
        padding:10px;
    }    
</style>
<?php
    $skin_url = $this->APP_STATIC_SERVER . '/skins/'. $this->APP_TEMPLATE . '/'. $this->APP_SKIN;
?>

<!--view message-->
<?php $this->addHelperPath(TOMATO_APP_DIR . DS . 'modules' . DS . 'shoppingcart' . DS . 'views' . DS . 'helpers', 'Shoppingcart_View_Helper');?>
<?php echo $this->message();?>
<!--end view message-->
<div class="grid_12"><?php echo $this->flashMessenger();?></div>
<div class="grid_12">
    <?php
        /**
        * Cart detail to view
        **/
        $cartDetails = $this->cartDetails;
    ?>
    <?php if(count($cartDetails) <= 0):?>
    <div class="cart">
    	<table>
            <tr class="caption">
                <td width="5%"><?php echo $this->translator('cart_item_remove');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_image');?></td>
                <td width="25%"><?php echo $this->translator('cart_item_name');?></td>
                <td width="10%"><?php echo $this->translator('cart_item_price');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_quantity');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_subtotal');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_action');?></td>
            </tr>
            <tr>
            	<td colspan="7"><?php echo $this->translator('not_found_item');?></td>
            </tr>
		</table>
		<div class="cart_bottom"></div>
        <div style="text-align:right;" class="inline_block cart_bottom amount">
            <div><label><?php echo $this->translator('cart_subtotal_amount')?></label>: 0</div>
            <div><label><?php echo $this->translator('cart_shipping_amount')?></label>: 0</div>
            <div><label><?php echo $this->translator('cart_total_amount')?></label>: 0</div>
        </div>		
	</div>
	<div class="inline_block">     
        <div style="text-align:center;"><a href="<?php echo $this->url(array(),'shop_product_all_products');?>"><?php echo $this->translator('cart_continue_button');?></a></div>        
    </div>    
    <?php else:?>
    
    <div><?php echo $this->flashMessenger();?></div>        
    <form action="" method="POST" id="cartForm">

    <?php foreach($this->arrayEnterpriseId as $r_id):?>

        <?php
            $arrayEnterpriseInfo = $this->arrayEnterpriseInfo[$r_id];            
            $arrProductsSorted =  $this->arrProductsSorted[$r_id];
            $shipping_priceSorted =  $this->shipping_priceSorted[$r_id];
            $subtotalSorted =  $this->subtotalSorted[$r_id];
            $arrAllAtValSorted =  $this->arrAllAtValSorted[$r_id];
            $arrayCartSorted =  $this->arrayCartSorted[$r_id];
        ?>

    <div class="cart">
        <div class="box subcolumns">
            <div class="cufon_title">
                <div class="inner">
                    <h3>
                        <?php echo $this->translator('cart_title_guide')?>:
                        <?php
                            $arrRouteEnterprise = array(
                                'enterprise_id' => $arrayEnterpriseInfo->id,
                                'enterprise_name' => Tomato_Utility_String::removeSign($arrayEnterpriseInfo->company_name_en, '-', true)
                            );
                            $enterpriseName = ($this->lang == 'vi_VN')?$arrayEnterpriseInfo->company_name_vn:$arrayEnterpriseInfo->company_name_en;
                        ?>
                        <a href="<?php echo $this->url($arrRouteEnterprise, 'bizprofile_enterprise_index'); ?>"><?php echo $enterpriseName;?></a>
                    </h3>
                </div>
            </div>
        </div>
        <table>
            <tr class="caption">
                <td width="5%"><?php echo $this->translator('cart_item_remove');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_image');?></td>
                <td width="25%"><?php echo $this->translator('cart_item_name');?></td>
                <td width="10%"><?php echo $this->translator('cart_item_price');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_quantity');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_subtotal');?></td>
                <td width="15%"><?php echo $this->translator('cart_item_action');?></td>
            </tr>
            <?php

            ?>
            <?php foreach($arrayCartSorted as $d_cart):?>
            <?php
                /**
                * Product info to view
                **/
                $product = $arrProductsSorted[$d_cart->id];
                $p_currency = $product['p_currency'];

                $arrAllAtVal = isset($arrAllAtValSorted[$d_cart->id])?$arrAllAtValSorted[$d_cart->id]:null;
                
                $arrOverQty = isset($this->arrOverQty[$d_cart->product_id])?$this->arrOverQty[$d_cart->product_id]:null;
            ?>
            <!--Hidden input-->
            <input type="hidden" name="cart_id[]" value="<?php echo $d_cart->id;?>"/>            
            <input type="hidden" name="product_id_<?php echo $d_cart->id;?>" value="<?php echo $d_cart->product_id;?>"/>

            <tr>
                <td><?php if(!$d_cart->cart_parent_id):?><input type="checkbox" name="cart_remove[]" value="<?php echo $d_cart->id;?>"/><?php endif;?>&nbsp;</td>
                <td><?php if($product['p_image']):?><img width="100" src="<?php echo $product['p_image'];?>" /><?php endif;?></td>
                <td>
                	<?php echo ($d_cart->cart_parent_id)?'---- ':null;?><?php echo $product['p_name'];?>
                    
                	<!--Bật tooltip thông báo khi mua vượt quá số lượng cho phép-->
                    <?php if(@$arrOverQty && !$d_cart->cart_parent_id):?>
                    <span id="errorTip_<?php echo $d_cart->id;?>" style="color:red; padding-left:20px; cursor:pointer;" >
                    	<?php echo $this->translator('shopping_cart_qty_error');?>
                    </span>                                        
                	<div id="divTip_<?php echo $d_cart->id;?>" class="tooltip">
            			<div><?php echo $this->translator('shopping_cart_qty_existed');?>: <b><?php echo $arrOverQty['qtyExisted'];?></b></div>
            			<div><?php echo $this->translator('shopping_cart_qty_allow');?>: <b><?php echo $arrOverQty['product_quantity'];?></b></div>
            		</div>
            		<script type="text/javascript" >						
					    $(document).ready(function(){					    	
					    	$("#errorTip_<?php echo $d_cart->id;?>").tooltip({ 
					    		effect: 'slide',					    		
					    		offset: [10, 2],
					    		opacity: 0.9,
					    		relative: true,
					    		tip: "#divTip_<?php echo $d_cart->id;?>"
					    	}).dynamic({ bottom: { direction: 'down', bounce: true } });    	
					    });
    				</script>
            		<?php endif;?>
            		<!--Kết thúc bật tooltip-->
                                    
                    <?php if($arrAllAtVal):?>                    
                    <div class="view_detail">
                    	<?php echo ($d_cart->cart_parent_id)?'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;':null;?><img title="<?php echo $arrAllAtVal;?>" style="cursor:pointer" src="<?php echo $skin_url;?>/images/info_btn.png" />
                    <label style="cursor:pointer" title="<?php echo $arrAllAtVal;?>"><?php echo $this->translator('cart_view_details')?></label>
					</div>
                    <?php endif;?>                    
                </td>
                <td><?php echo $product['p_price'];?> <i><?php echo $product['p_currency'];?></i></td>
                <td>        	
            		<?php if(!$d_cart->cart_parent_id):?>
            		<input style="width:100px; <?php if(@$arrOverQty && !$d_cart->cart_parent_id):?>color:red;<?php endif;?>" class="tipClose" rel="<?php echo $d_cart->id;?>" type="text" name="cart_quantity_<?php echo $d_cart->id;?>" value="<?php echo $d_cart->cart_quantity;?>" />
            		<?php else:?>
            		<input style="width:100px;" type="hidden" name="cart_quantity_<?php echo $d_cart->id;?>" value="<?php echo $d_cart->cart_quantity;?>" />
            		<?php echo $d_cart->cart_quantity;?>
            		<?php endif;?>
                </td>
                <td><?php if(!$d_cart->cart_parent_id):?><?php echo $product['total_price'];?> <i><?php echo $product['p_currency'];?></i><?php endif;?></td>

                <?php
                    /**
                    * Param url detail
                    **/
                    $arrUrlEndcode = array($d_cart->id, rand(5,10000));
                    $urlEncode = rawurlencode(base64_encode(Zend_Json::encode($arrUrlEndcode)));
                    $arrRouteDetail = array(
                        'enterprise_id' => $product['e_id'],
                        'enterprise_name' => Tomato_Utility_String::removeSign($product['e_name'], '-', true),
                        'cat' => $product['c_id'],
                        'slug' => ($product['c_slug'])?$product['c_slug']:Tomato_Utility_String::removeSign($product['c_name'], '-', true),
                        'product_id' => $d_cart->product_id,
                        'pro_slug' => ($product['p_slug'])?$product['p_slug']:Tomato_Utility_String::removeSign($product['p_name'], '-', true),
                    );
                ?>
                <td>
                    <?php if($arrAllAtVal):?>
                    <a href="<?php echo $this->url($arrRouteDetail,'shop_product_detail');?>/?p=<?php echo $urlEncode;?>"> <?php echo $this->translator('cart_change_detail');?></a>
                    <?php else:?>
                    -
                    <?php endif;?>
                </td>
            </tr>
            <?php endforeach;?>
        </table>
        <div class="cart_bottom"></div>
        <div style="text-align:right;" class="inline_block cart_bottom amount">
            <div><label><?php echo $this->translator('cart_subtotal_amount')?></label>: <?php echo $subtotalSorted;?> <i><?php echo $p_currency;?></i></div>
            <div><label><?php echo $this->translator('cart_shipping_amount')?></label>: <?php echo $shipping_priceSorted;?> <i><?php echo $p_currency;?></i></div>
            <div><label><?php echo $this->translator('cart_total_amount')?></label>: <?php echo $subtotalSorted+$shipping_priceSorted;?> <i><?php echo $p_currency;?></i></div>
        </div>
    </div>
    <?php endforeach;?>
    <div class="inline_block">
        <div class="col_33"><input type="submit" value="<?php echo $this->translator('cart_update_button');?>" /></div>
        <div class="col_33" style="text-align:center;"><a href="<?php echo $this->url(array(),'shop_product_all_products');?>"><?php echo $this->translator('cart_continue_button');?></a></div>
        <?php if($this->accept):?>
        <div class="col_33" style="text-align:right;"><a href="<?php echo $this->url(array(),'shoppingcart_shoppingcart_checkout');?>"><?php echo $this->translator('cart_checkout_button');?></a></div>
        <?php endif;?>
    </div>
    </form>
    <?php endif;?> 
</div>
<!--<script src="http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js"></script>-->
<script type="text/javascript" >
    $(document).ready(function(){    	
        // initialize tooltip
        $(".view_detail img[title],label[title]").tooltip({

            // tweak the position
            offset: [10, 2],

            // use the "slide" effect
            effect: 'slide',
            opacity: 0.9,
        // add dynamic plugin with optional configuration for bottom edge
        }).dynamic({ bottom: { direction: 'down', bounce: true } });        
    })
</script>